< previous page page_510 next page >

Page 510
Save and run the updated SQLVB02.SQV. You should see an SQL error message telling you that it could not find the table NewTable. This happened because the script executed the DROP TABLE statement just before the SELECT_FROM statement. The error message appears in Figure 13.10.
0510-01.jpg
Figure 13.10.
Results of the 
DROP TABLE statement.
Relationship SQL Keywords
You can create and delete indexes or constraints on a data table using the SQL keywords CREATE INDEX and DROP INDEX, and the CONSTRAINT clause of CREATE TABLE and ALTER TABLE statements. SQL constraints are just indexes with another name. However, CONSTRAINT clauses are usually used with CREATE TABLE statements to establish relationships between one or more tables in the same database. INDEX statements are usually used to add or delete search indexes to existing tables.
Managing Indexes with CREATE INDEX and DROP INDEX
The CREATE INDEX statement is used to create a search index on an existing table. The most basic form of the CREATE INDEX statement is shown in the following line:
CREATE INDEX NewIndex ON NewTable (Field1);
Several variations on the CREATE INDEX statement allow you to add data integrity to the data table. Table 13.2 shows a list of the various CREATE INDEX options and how they are used.
Table 13.2. The CREATE INDEX options.
CREATE INDEX StatementMeaning and Use
CREATE INDEX NewIndex ON NewTable(Field1) WITH PRIMARY Creates a primary key index. A primary key index ensures that each row of the table has a unique value in the index field. No nulls are allowed in the index field.
CREATE UNIQUE INDEX NewIndex ON NewTable(Field1)Creates a unique index on the designated field. In this example, no two columns could have the same value, but null values would be allowed.

(table continued on next page)

 
< previous page page_510 next page >

If you like this book, buy it!